<?php
/**
 * Created by JetBrains PhpStorm.
 * User: qiancheng
 * Date: 13-12-27
 * Time: 下午3:10
 * To change this template use File | Settings | File Templates.
 */

namespace Forxx;

use App\Api\Dao\PostSelfIndexTable;
use Forxx\Api\Dao\VIPProductTable;
use Forxx\Api\Dao\SerialTechTable;
use Forxx\Api\PublicList;

class SerialTech{

    public static function get_pub_by_sn($params)
    {
        return VIPProductTable::instance()->get(null,array('pub_id'),$params);
    }
    /*
     * 通过序列号获取技师ID
     */
    public static function get_tech_by_sn($params)
    {
        if(($data=SerialTechTable::instance()->get(null,array('tech_id'),$params))!=null)
        {
            return $data;
        }
        else
        {
            //如果设备未绑定技师，则返回公众号下所有的技师
            $pub=self::get_pub_by_sn($params);
            if(empty($pub[0]))
            {
                return false;
            }
            $data=PublicList::list_tech_byp($pub[0]);
            foreach($data as $key=>$value)
            {
                $tech[$key]['tech_id']=$value['tech_id'];
            }
            return $tech;
        }
    }
    public static function get_tech_by_pub($params)
    {
        $param['pub_id']=$params['pub_id'];
        return PublicList::list_tech_byp($param);
    }
}